﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Channels;
using System.Text;

namespace ElectronicCommerce.Framework.ServiceModel.WCF.TransferElement
{
    internal static class BindingFactory
    {
        public static IGetBindingByConfig CreateHandler(BindingTypeEnum bindingType)
        {
            string className = "ElectronicCommerce.Framework.ServiceModel." + bindingType.ToString() + "Handler";
            Type type = Type.GetType(className);

            if (type != null)
            {
                return (IGetBindingByConfig)Activator.CreateInstance(type);
            }
            else
            {
                throw new Exception(className + " is not exist.");
            }
        }

        public static Binding GetBindingMsgByConfig(string configStr, BindingTypeEnum bindingType)
        {
            IGetBindingByConfig handler = CreateHandler(bindingType);
            return handler.GetBindingMsgByConfig(configStr);
        }

        public static string GetAddress(string templateAddress, BindingTypeEnum bindingType)
        {
            IGetBindingByConfig handler = CreateHandler(bindingType);
            return handler.GetAddress(templateAddress);
        }
    }
}
